package com.ruoyi.web.controller.mall.menNeedInfo.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.controller.mall.mallShopUser.domain.MallShopUser;
import com.ruoyi.web.controller.mall.mallShopUser.service.IMallShopUserService;
import com.ruoyi.web.controller.mall.menNeedInfo.domain.MenNeedInfo;
import com.ruoyi.web.controller.mall.menNeedInfo.service.IMenNeedInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 需求详情Controller
 * 
 * @author ruoyi
 * @date 2021-01-18
 */
@RestController
@RequestMapping("/mall/menNeedInfo")
public class MenNeedInfoController extends BaseController
{
    @Autowired
    private IMenNeedInfoService menNeedInfoService;
    @Autowired
    private IMallShopUserService mallShopUserService;

    /**
     * 查询需求详情列表
     */
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody Map<String,Object> map)
    {
        MallShopUser msu = mallShopUserService.selectMallShopUserById(map.get("shopId").toString());
        if (msu!=null){
            map.put("shopId",msu.getUserId());
        }
        startPage();
        List<Map<String,Object>> list = menNeedInfoService.selectMenNeedInfoList(map);
        return getDataTable(list);
    }

    /**
     * 获取商品规格名详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:notice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        MenNeedInfo menNeedInfo = menNeedInfoService.selectMenNeedInfoById(id);
        return AjaxResult.success(menNeedInfo);
    }

    /**
     * 导出需求详情列表
     */
    @Log(title = "需求详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(MenNeedInfo menNeedInfo)
    {
//        List<MenNeedInfo> list = menNeedInfoService.selectMenNeedInfoList(menNeedInfo);
//        ExcelUtil<MenNeedInfo> util = new ExcelUtil<MenNeedInfo>(MenNeedInfo.class);
//        return util.exportExcel(list, "menNeedInfo");
        return null;
    }

    /**
     * 新增保存需求详情
     */
    @Log(title = "需求详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addSave(@RequestBody MenNeedInfo menNeedInfo)
    {
        MallShopUser msu = mallShopUserService.selectMallShopUserById(menNeedInfo.getShopId());
        menNeedInfo.setId(StringUtils.get32UUID());
        menNeedInfo.setUserId(msu.getUserId());
        menNeedInfo.setCaAt(DateUtils.getNowDate());
        menNeedInfo.setDelFlag(0);
        menNeedInfo.setRecommend(0);
        menNeedInfo.setStatus(1);
        return toAjax(menNeedInfoService.insertMenNeedInfo(menNeedInfo));
    }

    /**
     * 修改保存需求详情
     */
//    @Log(title = "需求详情", businessType = BusinessType.UPDATE)
//    @PostMapping("/edit")
//    @ResponseBody
//    public AjaxResult editSave(@RequestBody MenNeedInfo menNeedInfo)
//    {
//        return toAjax(menNeedInfoService.updateMenNeedInfo(menNeedInfo));
//    }

    /**
     * 删除需求详情
     */
    @Log(title = "需求详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    public AjaxResult remove(@RequestBody MenNeedInfo menNeedInfo)
    {
        return toAjax(menNeedInfoService.deleteMenNeedInfoById(menNeedInfo.getId()));
    }
}
